// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import global from './global'
import SIdentify from './components/identify'
Vue.component('s-identify', SIdentify)

Vue.prototype.GLOBAL = global
Vue.config.productionTip = false

router.beforeEach(function (to, from, next) {
  if (to.meta.isLogin) {
    // 页面是否登录
    if (localStorage.getItem('baoShi_Token')) {
      // 本地存储中是否有token(uid)数据
      next() // 表示已经登录
    } else {
      // next可以传递一个路由对象作为参数 表示需要跳转到的页面
      next({
        name: 'login'
      })
    }
  } else {
    // 表示不需要登录
    next() // 继续往后走
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
